package com.xiaoyg.lock;

import java.util.ArrayList;
import java.util.List;

/**
 * 定义一个共享变量number
 * 对number进行1000次的++操作
 * 使用5个线程操作
 */
public class TestAtomicity {

    private static int number = 0;

    public static void main(String[] args) {
        Runnable runnable = ()->{
            for (int i = 0; i < 1000; i++) {
                /**
                 *   9: getstatic     #9                  // Field number:I
                 *   12: iconst_1
                 *   13: iadd
                 *   14: putstatic     #9                  // Field number:I
                 */
                number++;
            }
        };

        List<Thread> list = new ArrayList<>();

        for (int i = 0; i < 5; i++) {
            Thread thread = new Thread(runnable);
            thread.start();
            list.add(thread);
        }
    }

}
